#!/bin/bash
clear
ls /home/wwwroot/
echo
read -p "请输入以上站点对应的目录名称："  SSJQ
read -p  "请输入 网站标识："  ZDMC

JCZD=`ls /home/wwwroot/${SSJQ}/ | grep ${ZDMC} | wc -l`
if [ "$JCZD" != 1 ];then
   echo " 目录${SSJQ}中，不存在${ZDMC}！！ "
   exit
fi

clear
echo -e "\033[33m 注意一切输入的内容，头和尾都不要带空格！！和修改代码文件一样！！\033[0m"
echo
read -p  "请输入 前台网站接口地址 列如：http://b029_xy6.dggcolligate.com  ："  QTJKDZ
read -p  "请输入 后台接口地址 列如：http://b029_xy6.dggcolligateadmin.com  ："  HTJKDZ
read -p  "请输入 运行nodejs机器的内网ip："  NDIP
read -p  "请输入 本站点nodejs的端口号："  NDH
read -p  "请输入 聊天室ID："   LTID
read -p  "请输入 综合 AES 密钥："  AESMY
read -p  "请输入 综合 MD5 密钥："  MD5MY
read -p  "请输入 B站访问地址 列如：http://dgg666.zadan123.com/  ："    BZFWDZ
read -p  "请输入 拉单系统访问地址 列如：http://ladan.dgg8888.com/  ："    LDFWDZ
read -p  "请输入 B站AES密钥："    BZAES
read -p  "请输入 B站MD5密钥："    BZMD5
read -p  "请输入 B站代理编号："   BZDLBH
read -p  "请输入 B站对应标识："   BZDYBS


#修改第一个文件
DIRadmin1=/home/wwwroot/"$SSJQ"/"$ZDMC"/admin/application/config/config.php

#$config['nodejs'] = 'http://192.168.1.108:15531';
ZZ1=`cat -n ${DIRadmin1}  | grep 'nodejs' | awk '{print $1}'`
sed -i ''"$ZZ1"'c $config['"'nodejs'"'] = '"'http://"$NDIP":"$NDH"'"';'  ${DIRadmin1}

#$config['website'] = 'b030';       //网站标识设置
ZZ2=`cat -n ${DIRadmin1} | grep 'website' | awk '{print $1}'`
sed -i ''"$ZZ2"'c $config['"'website'"'] = '"'"$ZDMC"'"';   //网站标识设置'  ${DIRadmin1}

#$config['kj_host'] = 'kj.b030.com';	//开奖host域名
ZZ3=`cat -n ${DIRadmin1} | grep 'kj_host' | awk '{print $1}'`
sed -i ''"$ZZ3"'c $config['"'kj_host'"'] = '"'"kj.${ZDMC}.com"'"';   //开奖host域名'   ${DIRadmin1}

#$config['upyun_image_dir'] = '/b030/';// 本站 图片所在的目录 目录可自行设置
ZZ4=`cat -n ${DIRadmin1} | grep 'upyun_image_dir' | awk '{print $1}'`
sed -i ''"$ZZ4"'c $config['"'upyun_image_dir'"'] = '"'"/${ZDMC}/"'"';   //本站图片所在的目录 目录可自行设置'  ${DIRadmin1}

#$config['chatID'] = '78621596254209';	//聊天室ID
ZZ5=`cat -n ${DIRadmin1} | grep 'chatID' | awk '{print $1}'`
sed -i ''"$ZZ5"'c $config['"'chatID'"'] = '"'"${LTID}"'"';   //聊天室ID'  ${DIRadmin1}

#$config['aesKey'] = 'ajt4vnvstfqf5mnv';	 //AES密钥
ZZ6=`cat -n ${DIRadmin1} | grep 'aesKey' | grep -v 'Bz_aesKey' | awk '{print $1}'`
sed -i ''"$ZZ6"'c $config['"'aesKey'"'] = '"'"${AESMY}"'"';   //AES密钥'   ${DIRadmin1}

#$config['md5Key'] = 'wc1quxfb1beycqc7';	 //MD5密钥
ZZ7=`cat -n ${DIRadmin1} | grep 'md5Key'  | grep -v 'Bz_md5Key' | awk '{print $1}'`
sed -i ''"$ZZ7"'c $config['"'md5Key'"'] = '"'"${MD5MY}"'"';   //MD5密钥'   ${DIRadmin1}

#$config['Bz_http'] = 'http://dgg666.zadan123.com/';		//B站访问地址
ZZ8=`cat -n ${DIRadmin1} | grep 'Bz_http' | awk '{print $1}'`
sed -i ''"$ZZ8"'c $config['"'Bz_http'"'] = '"'"${BZFWDZ}"'"';   //B站访问地址'   ${DIRadmin1}

#$config['Ld_http'] = 'http://ladan.dgg8888.com/';	//拉单系统访问地址
ZZ9=`cat -n ${DIRadmin1} | grep 'Ld_http' | awk '{print $1}'`
sed -i ''"$ZZ9"'c $config['"'Ld_http'"'] = '"'"${LDFWDZ}"'"';   //拉单系统访问地址'   ${DIRadmin1}

#$config['Bz_aesKey'] = '979a0e21c0b4338ed93060df6414b02f';		//B站AES密钥   
ZZ10=`cat -n ${DIRadmin1} | grep 'Bz_aesKey' | awk '{print $1}'`
sed -i ''"$ZZ10"'c $config['"'Bz_aesKey'"'] = '"'"${BZAES}"'"';   //B站AES密钥'   ${DIRadmin1}

#$config['Bz_md5Key'] = 'c83d2ff374386132d035acf538ae63d8';		//B站MD5密钥  
ZZ11=`cat -n ${DIRadmin1} | grep 'Bz_md5Key' | awk '{print $1}'`
sed -i ''"$ZZ11"'c $config['"'Bz_md5Key'"'] = '"'"${BZMD5}"'"';   //B站MD5密钥'   ${DIRadmin1}

#$config['Bz_agent'] = '23220461';	 //B站代理编号
ZZ12=`cat -n ${DIRadmin1} | grep 'Bz_agent' | awk '{print $1}'`
sed -i ''"$ZZ12"'c $config['"'Bz_agent'"'] = '"'"${BZDLBH}"'"';   //B站代理编号'   ${DIRadmin1}

#$config['Bz_iden'] = 'JH';		//B站对应标识   
ZZ13=`cat -n ${DIRadmin1} | grep 'Bz_iden' | awk '{print $1}'`
sed -i ''"$ZZ13"'c $config['"'Bz_iden'"'] = '"'"${BZDYBS}"'"';   //B站对应标识'   ${DIRadmin1}

dos2unix  ${DIRadmin1}








read -p "请输入数据库的vip内网地址："  MYSQLVIP
read -p "请输入本站点的数据库名称：列 B030："  MYSQLDB
read -p "请输入站点的mysql用户，请用单引号 列：'mysl的密码'："  MYSQLPA


#修改第二个文件
DIRadmin2=/home/wwwroot/"$SSJQ"/"$ZDMC"/admin/application/config/database.php

#'hostname' => 'mysql:host=192.168.1.50;dbname=B030',
YY1=`cat -n ${DIRadmin2} | grep mysql:host | awk '{print $1}'`
sed -i ''"$YY1"'c '"'hostname'"' => '"'"mysql:host=${MYSQLVIP}\;dbname=${MYSQLDB}"'"','   ${DIRadmin2}

#'username' => 'B030user',
YY2=`cat -n ${DIRadmin2} | grep username | grep '=>' | awk '{print $1}'`
sed -i ''"$YY2"'c '"'username'"' => '"'"${MYSQLDB}user"'"','   ${DIRadmin2}

#'password' => '6EBHzBCBEGPSmvMJCQbl',
YY3=`cat -n ${DIRadmin2} | grep password | grep '=>' | awk '{print $1}'`
sed -i ''"$YY3"'c '"'password'"' => '""${MYSQLPA}""','   ${DIRadmin2}

#'database' => 'B030',
YY4=`cat -n ${DIRadmin2} | grep database | grep '=>'  | awk '{print $1}'`
sed -i ''"$YY4"'c '"'database'"' => '"'"${MYSQLDB}"'"','   ${DIRadmin2}

dos2unix  ${DIRadmin2}








#read -p  "请输入 后台接口地址 列如：http://b029_xy6.dggcolligateadmin.com  ："  HTJKDZ
#read -p  "请输入 前台网站接口地址 列如：http://b029_xy6.dggcolligate.com  ："  QTJKDZ


#修改第三个文件
DIRadmin3=/home/wwwroot/"$SSJQ"/"$ZDMC"/adminweb/config.js

#window.host="http://b030_th9.dggcolligateadmin.com";
YY5=`cat -n ${DIRadmin3} | grep window.host  | awk '{print $1}'`
sed -i ''"$YY5"'c  window.host="'""$HTJKDZ""'";'   ${DIRadmin3}

dos2unix  ${DIRadmin3}









#修改第四个文件
DIRadmin4=/home/wwwroot/"$SSJQ"/"$ZDMC"/index/application/config/config.php

#$config['nodejs'] = 'http://192.168.1.108:15531';
XX1=`cat -n ${DIRadmin4}  | grep 'nodejs' | awk '{print $1}'`
sed -i ''"$XX1"'c $config['"'nodejs'"'] = '"'http://"$NDIP":"$NDH"'"';'  ${DIRadmin4}

#$config['website'] = 'b030';       //网站标识设置
XX2=`cat -n ${DIRadmin4} | grep 'website' | awk '{print $1}'`
sed -i ''"$XX2"'c $config['"'website'"'] = '"'"$ZDMC"'"';   //网站标识设置'  ${DIRadmin4}

#$config['upyun_image_dir'] = '/b030/';// 本站 图片所在的目录 目录可自行设置
XX4=`cat -n ${DIRadmin4} | grep 'upyun_image_dir' | awk '{print $1}'`
sed -i ''"$XX4"'c $config['"'upyun_image_dir'"'] = '"'"/${ZDMC}/"'"';   //本站图片所在的目录 目录可自行设置'  ${DIRadmin4}

#$config['chatID'] = '78621596254209';	//聊天室ID
XX5=`cat -n ${DIRadmin4} | grep 'chatID' | awk '{print $1}'`
sed -i ''"$XX5"'c $config['"'chatID'"'] = '"'"${LTID}"'"';   //聊天室ID'  ${DIRadmin4}

#$config['aesKey'] = 'ajt4vnvstfqf5mnv';	 //AES密钥
XX6=`cat -n ${DIRadmin4} | grep 'aesKey' | grep -v 'Bz_aesKey' | awk '{print $1}'`
sed -i ''"$XX6"'c $config['"'aesKey'"'] = '"'"${AESMY}"'"';   //AES密钥'   ${DIRadmin4}

#$config['md5Key'] = 'wc1quxfb1beycqc7';	 //MD5密钥
XX7=`cat -n ${DIRadmin4} | grep 'md5Key'  | grep -v 'Bz_md5Key' | awk '{print $1}'`
sed -i ''"$XX7"'c $config['"'md5Key'"'] = '"'"${MD5MY}"'"';   //MD5密钥'   ${DIRadmin4}

#$config['Bz_http'] = 'http://dgg666.zadan123.com/';		//B站访问地址
XX8=`cat -n ${DIRadmin4} | grep 'Bz_http' | awk '{print $1}'`
sed -i ''"$XX8"'c $config['"'Bz_http'"'] = '"'"${BZFWDZ}"'"';   //B站访问地址'   ${DIRadmin4}

#$config['Ld_http'] = 'http://ladan.dgg8888.com/';	//拉单系统访问地址
XX9=`cat -n ${DIRadmin4} | grep 'Ld_http' | awk '{print $1}'`
sed -i ''"$XX9"'c $config['"'Ld_http'"'] = '"'"${LDFWDZ}"'"';   //拉单系统访问地址'   ${DIRadmin4}

#$config['Bz_aesKey'] = '979a0e21c0b4338ed93060df6414b02f';		//B站AES密钥   
XX10=`cat -n ${DIRadmin4} | grep 'Bz_aesKey' | awk '{print $1}'`
sed -i ''"$XX10"'c $config['"'Bz_aesKey'"'] = '"'"${BZAES}"'"';   //B站AES密钥'   ${DIRadmin4}

#$config['Bz_md5Key'] = 'c83d2ff374386132d035acf538ae63d8';		//B站MD5密钥  
XX11=`cat -n ${DIRadmin4} | grep 'Bz_md5Key' | awk '{print $1}'`
sed -i ''"$XX11"'c $config['"'Bz_md5Key'"'] = '"'"${BZMD5}"'"';   //B站MD5密钥'   ${DIRadmin4}

#$config['Bz_agent'] = '23220461';	 //B站代理编号
XX12=`cat -n ${DIRadmin4} | grep 'Bz_agent' | awk '{print $1}'`
sed -i ''"$XX12"'c $config['"'Bz_agent'"'] = '"'"${BZDLBH}"'"';   //B站代理编号'   ${DIRadmin4}

#$config['Bz_iden'] = 'JH';		//B站对应标识   
XX13=`cat -n ${DIRadmin4} | grep 'Bz_iden' | awk '{print $1}'`
sed -i ''"$XX13"'c $config['"'Bz_iden'"'] = '"'"${BZDYBS}"'"';   //B站对应标识'   ${DIRadmin4}

dos2unix  ${DIRadmin4}








#修改第五个文件
DIRadmin5=/home/wwwroot/"$SSJQ"/"$ZDMC"/index/application/config/database.php

#'hostname' => 'mysql:host=192.168.1.50;dbname=B030',
XX14=`cat -n ${DIRadmin5} | grep mysql:host | awk '{print $1}'`
sed -i ''"$XX14"'c '"'hostname'"' => '"'"mysql:host=${MYSQLVIP}\;dbname=${MYSQLDB}"'"','   ${DIRadmin5}

#'username' => 'B030user',
XX15=`cat -n ${DIRadmin5} | grep username | grep '=>' | awk '{print $1}'`
sed -i ''"$XX15"'c '"'username'"' => '"'"${MYSQLDB}user"'"','   ${DIRadmin5}

#'password' => '6EBHzBCBEGPSmvMJCQbl',
XX16=`cat -n ${DIRadmin5} | grep password | grep '=>' | awk '{print $1}'`
sed -i ''"$XX16"'c '"'password'"' => '""${MYSQLPA}""','   ${DIRadmin5}

#'database' => 'B030',
XX17=`cat -n ${DIRadmin5} | grep database | grep '=>'  | awk '{print $1}'`
sed -i ''"$XX17"'c '"'database'"' => '"'"${MYSQLDB}"'"','   ${DIRadmin5}

dos2unix  ${DIRadmin5}




#修改第六个文件
DIRadmin6=/home/wwwroot/"$SSJQ"/"$ZDMC"/kaijiang/configpz.js

#global.myhost = 'kj.b030.com';
WW1=`cat -n ${DIRadmin6} | grep global.myhost  | awk '{print $1}'`
sed -i ''"$WW1"'c '"global.myhost"' = '"'"kj.${ZDMC}.com"'"';'   ${DIRadmin6}

#global.dbhost = '192.168.1.50';
WW2=`cat -n ${DIRadmin6} | grep global.dbhost  | awk '{print $1}'`
sed -i ''"$WW2"'c '"global.dbhost"' = '"'"${MYSQLVIP}"'"';'   ${DIRadmin6}

#global.dbname = 'B030';
WW3=`cat -n ${DIRadmin6} | grep global.dbname  | awk '{print $1}'`
sed -i ''"$WW3"'c '"global.dbname"' = '"'"${MYSQLDB}"'"';'   ${DIRadmin6}

#global.dbuser = 'B030user';
WW4=`cat -n ${DIRadmin6} | grep global.dbuser  | awk '{print $1}'`
sed -i ''"$WW4"'c '"global.dbuser"' = '"'"${MYSQLDB}user"'"';'   ${DIRadmin6}

#global.dbpass = '6EBHzBCBEGPSmvMJCQbl';
WW5=`cat -n ${DIRadmin6} | grep global.dbpass  | awk '{print $1}'`
sed -i ''"$WW5"'c '"global.dbpass"' = '""${MYSQLPA}""';'   ${DIRadmin6}

#global.port = '15532';
WW6=`cat -n ${DIRadmin6} | grep global.port  | awk '{print $1}'`
sed -i ''"$WW6"'c '"global.port"' = '"'"${NDH}"'"';'   ${DIRadmin6}

dos2unix  ${DIRadmin6}




#修改第七个文件
DIRadmin7=/home/wwwroot/"$SSJQ"/"$ZDMC"/web/config.js

#window.host="http://b030_th9.dggcolligate.com"; 
WW7=`cat -n ${DIRadmin7} | grep window.host  | awk '{print $1}'`
sed -i ''"$WW7"'c  window.host="'""$QTJKDZ""'";'   ${DIRadmin7}
  
#window.aes="ajt4vnvstfqf5mnv";      
WW8=`cat -n ${DIRadmin7} | grep window.aes  | awk '{print $1}'`
sed -i ''"$WW8"'c  window.aes="'""$AESMY""'";'   ${DIRadmin7}

#window.md5="wc1quxfb1beycqc7";      
WW9=`cat -n ${DIRadmin7} | grep window.md5  | awk '{print $1}'`
sed -i ''"$WW9"'c  window.md5="'""$MD5MY""'";'   ${DIRadmin7}

dos2unix  ${DIRadmin7}



clear
echo
echo  "代码文件修改成功"


